<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MAC/RLC信令查询</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.4.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.4.4/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
var page=0;
var lasttime;

function getCommontData() {
	var startTime=$("#i1").datebox("getValue");
	var endTime=$("#i2").datebox("getValue");
	var IMSI = $("#IMSI").val();
	var MSISDN = $("#MSISDN").val();
	var MessageType = $("#messageType1").combotree("getText");
	var TLLI = $("#TLLI").val();
	
	var tlli = TLLI.length > 0 ? parseInt(TLLI,16):'';
	
	var recordId = $("#recordId").val();
	var SourceIP = $("#SourceIP").val();
	var DestinationIP = $("#DestinationIP").val();
	startDate = new Date(startTime.replace(new RegExp("-","gm"),"/"));
	endDate = new Date(endTime.replace(new RegExp("-","gm"),"/"));
	var startTimeLong = startDate.getTime();
	var endTimeLong = endDate.getTime();
	var BSName = $("#BSName").combotree("getText");;
	var gTrainNo = '';
	var gEngineNo = '';
	if ($('#in1').searchbox('getName') == 'IMSI') {
		IMSI = $('#in1').searchbox('getValue');
	} else if ($('#in1').searchbox('getName') == 'gTrainNo') {
		gTrainNo = $('#in1').searchbox('getValue');
	} else if ($('#in1').searchbox('getName') == 'CTCS_ID') {
		gEngineNo = $('#in1').searchbox('getValue');
	}
	
	
	return {"startTime":startTimeLong, "endTime":endTimeLong, "IMSI":IMSI, "MSISDN": MSISDN, "recordId": recordId, "BSName": BSName,
		"MessageType":MessageType, "TLLI":tlli, "SourceIP":SourceIP, "DestinationIP":DestinationIP,"gEngineNo":gEngineNo,"gTrainNo":gTrainNo};
}

function searchGPRS_default(){
	page=1;
	
	var data = getCommontData();
	
	if(data.startTime - data.endTime > 0){
		$.messager.alert("系统提示","查询开始时间不能大于结束时间！");
		return;
	}
	sendData(data, '1', page);
}

function sendData(data, increase, page) {
	var currentpage="第 "+page+" 页";
	var p=$("#dg" ).datagrid("getPager" )
	$(p).pagination({ //设置分页页数
		displayMsg:currentpage
   	});
	
	var IMSI = data.IMSI;
	if (IMSI != null && IMSI.length > 0) {
		
		var startTime=$("#i1").datebox("getValue");
		var endTime=$("#i2").datebox("getValue");
		startDate = new Date(startTime.replace(new RegExp("-","gm"),"/"));
		endDate = new Date(endTime.replace(new RegExp("-","gm"),"/"));
		var startTimeLong = startDate.getTime();
		var endTimeLong = endDate.getTime();
		
		$.post("${pageContext.request.contextPath}/gprs_full/findTLLI.do",{IMSI:data.IMSI,"startTime":startTimeLong,
			"endTime":endTimeLong,},function(result){
			
			var TLLIs = result.messageContent.toString();
			if (TLLIs != null && TLLIs.length > 0 && data.TLLI != null) {
				TLLIs += (',' + data.TLLI);
			} else if (data.TLLI != null) {
				TLLIs = data.TLLI;
			}
			console.log('TLLIs = ' + TLLIs);
			$("#dg").datagrid('load',{
				"startTime":data.startTime,
				"endTime":data.endTime,
				"MSISDN":data.MSISDN,
				"MessageType":data.MessageType,
				"TLLIs":TLLIs,
				"SourceIP":data.SourceIP,
				"DestinationIP":data.DestinationIP,
				"search":'1',
				"increase":increase,
				"recordId": data.recordId,
				"gEngineNo":data.gEngineNo,
				"gTrainNo":data.gTrainNo,
				"BSName": data.BSName
			});
		},"json");
	} else {
		$("#dg").datagrid('load',{
			"startTime":data.startTime,
			"endTime":data.endTime,
			"MSISDN":data.MSISDN,
			"MessageType":data.MessageType,
			"TLLI":data.TLLI,
			"SourceIP":data.SourceIP,
			"DestinationIP":data.DestinationIP,
			"search":'1',
			"increase":increase,
			"recordId": data.recordId,
			"gEngineNo":data.gEngineNo,
			"gTrainNo":data.gTrainNo,
			"BSName": data.BSName
		});
	}
}

function searchNext(){
	var size=$("#dg" ).datagrid("getPager" ).data("pagination" ).options.pageSize;
	var rows  = $('#dg').datagrid("getRows");  
	if(rows.length<size){
		$.messager.alert("系统提示","当前页已经是最后一页！");
		return;
	} else {
		lasttime=rows[rows.length-1].unixTimeStamp;
	}
	
	var data = getCommontData();
	
	data.startTime = lasttime;
	page=page+1;

	sendData(data, '1', page);
}

function searchBack(){
	if(page==1){
		$.messager.alert("系统提示","当前页已经是第一页！");
		 return;
	}
	
	var data = getCommontData();
	var rowsbefore  = $('#dg').datagrid("getRows"); 
	if(rowsbefore.length>0){
		data.endTime = rowsbefore[0].unixTimeStamp;
	} else {
		data.endTime = lasttime;
	}
	page=page-1;
	
	sendData(data, '0', page);
}
	
	function formatDatebox(value) {
	 	var datetimeType = "";
	    var date =new Date(parseInt(value));
	    datetimeType = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()
	    +" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+" "+date.getMilliseconds();
	    return datetimeType;
	}
	
	function postExcelFile(params, url) { //params是post请求需要的参数，url是请求url地址
	    var form = document.createElement("form");
	    form.style.display = 'none';
	    form.action = url;
	    form.method = "post";
	    document.body.appendChild(form);

	    for(var key in params){
	      var input = document.createElement("input");
	      input.type = "hidden";
	      input.name = key;
	      input.value = params[key];
	      form.appendChild(input);
	    }
	    form.submit();
	    form.remove();
	}
	function exportGprs_defaultInCurrentPage(){
		var rows  = $('#dg').datagrid("getRows");
		if (rows.length < 1) {
			$.messager.alert("系统提示", "请查询需要导出的数据");
			return;
		}
    	var params = {data:JSON.stringify(rows)};
    	postExcelFile(params, "${pageContext.request.contextPath}/gprs_default/exportcurrentpage.do");
	}
	function exportByTemplateInCurrentPage(){
		var rows = $("#dg").datagrid("getRows");
		var strIds=[];
		 for(var i=0;i<rows.length;i++){
			 strIds.push(rows[i].id);
		 }
		 var ids=strIds.join(",");
		 window.open('${pageContext.request.contextPath}/gprs_default/exportByTemplate.do?ids='+ids+'');
	}
	
	function exportGprs_defaultInAllPages(){
		var data = getCommontData();
		
		var IMSI = data.IMSI;
		
		if (IMSI != null && IMSI.length > 0) {
			$.post("${pageContext.request.contextPath}/gprs_full/findTLLI.do",{IMSI:data.IMSI,"startTime":data.startTime,
				"endTime":data.endTime,},function(result){
				
				var TLLIs = result.messageContent;
				
				var TLLIs = result.messageContent.toString();
				if (TLLIs != null && TLLIs.length > 0 && data.TLLI != null) {
					TLLIs += (',' + data.TLLI);
				} else if (data.TLLI != null) {
					TLLIs = data.TLLI;
				}
				console.log(TLLIs);
				window.open('${pageContext.request.contextPath}/gprs_default/export.do?startTime='+data.startTime+'&endTime='+data.endTime+'&TLLIs='+TLLIs+'&MessageType='+data.MessageType+'&BSName='+data.BSName+'&recordId='+data.recordId);
				
			},"json");
		} else {
			window.open('${pageContext.request.contextPath}/gprs_default/export.do?startTime='+data.startTime+'&endTime='+data.endTime+'&IMSI='+data.IMSI+'&MessageType='+data.MessageType+'&TLLI='+data.TLLI+'&BSName='+data.BSName+'&recordId='+data.recordId);
		}
		
		
		
	}
	
	function exportByTemplateInAllPages(){
		 window.open('${pageContext.request.contextPath}/gprs_default/exportByTemplate.do?ids='+null+'');
	}
	//重写分页
	$(function(){
		
		var p = $('#dg').datagrid('getPager');
	    $(p).pagination({ //设置分页功能栏
	           //分页功能可以通过Pagination的事件调用后台分页功能来实现
	            //layout:['prev','next'],
                layout:['list','sep'],
                /* beforePageText: '第',//页数文本框前显示的汉字 
                afterPageText: '页', */
	            displayMsg:"",   
	            buttons:[{
	    			iconCls:'icon-undo',
	    			handler:function(){ searchGPRS_default(); }
	    		},{
	    			iconCls:'icon-back',
	    			handler:function(){ searchBack(); }
	    		}, {
	    			iconCls:'icon-next',
	    			handler:function(){ searchNext(); }
	    		}]
	    });
	    
	    $('#messageType1').combotree('loadData', [{id:'1000', text:'全选', children:[
		    {id:'0', text:'Channel Request'},
		    {id:'1', text:'EGPRS Packet Downlink Ack/Nack Type 3 message content'},
		    {id:'2', text:'EGPRS Packet Downlink Ack/Nack DLMC message content'},
		    {id:'3', text:'MBMS Downlink Ack/Nack message content'},
	    	{id:'4', text:'Packet Uplink Assignment message content'},
		    {id:'5', text:'Packet Downlink Assignment message content'},
		    {id:'6', text:'Packet Power Control/Timing Advance message content'},
		    {id:'7', text:'Packet Uplink Ack/Nack message content'},
		    {id:'9', text:'Packet Polling Request message content'},
		    {id:'10', text:'Packet TBF Release message content'},
		    {id:'11', text:'Packet Resource Request message content'},
		    {id:'12', text:'Packet Downlink Ack_OR_Nack message content'},
		    {id:'13', text:'Packet Cell Change Notification message content'},
		    {id:'14', text:'Packet CS Request message content'},
		    {id:'15', text:'Packet Measurement Report message content'},
		    {id:'16', text:'Time Slot Reconfig message content'},
		    {id:'8', text:'PSI13 message content'},
		    {id:'17', text:'PSI14 message content'},
		    {id:'18', text:'Immediate Assignment'}]}]);
	    
	    $('#BSName').combotree({
	    	url: '${pageContext.request.contextPath}/sdcch/sdcchDistrictComboList.do'
	    });
	    
	    $('#i1').datetimebox('setValue', formatterDate(new Date(new Date(new Date().toLocaleDateString()).getTime())));
		$('#i2').datetimebox('setValue', formatterDate(new Date()));
		$('.searchbox-button').remove();
	});
	
	formatterDate = function (date) {
		var day = date.getDate();
		var month = (date.getMonth() + 1);
		var hor = date.getHours();
		var min = date.getMinutes();
		var sec = date.getSeconds();
		return date.getFullYear() + '-' + month + '-' + day+" "+hor+":"+min+":"+sec;
	};
</script>
</head>
<body style="margin: 1px">
<table id="dg" title="MAC/RLC信令查询管理" class="easyui-datagrid"
   fitColumns="false" pagination="true" rownumbers="true" pageSize="100" pageList="[100,200,300,400,500]"
   url="${pageContext.request.contextPath}/gprs_default/list.do" fit="true" toolbar="#tb">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<th field="startTime" width="140" align="center">触发时间</th>
   		<th field="IMSI" width="80" align="center">IMSI</th>
   		<th field="TLLI" width="80" align="center">TLLI</th>
   		<th field="BCCH" width="80" align="center">BCCH</th>
   		<th field="TCH" width="80" align="center">TCH</th>
   		<th field="timeSlot" width="80" align="center">时隙号</th>
		<th field="USF" width="80" align="center">USF</th>
		<th field="TFI" width="80" align="center">TFI</th>
   		<th field="frameNumber" width="80" align="center">帧号</th>
   		<th field="gEngineNo" width="80" align="center">机车号</th>
   		<th field="gTrainNo" width="80" align="center">车次号</th>
   		<th field="BSName" width="80" align="center">小区名称</th>
   		<th field="direction" width="80" align="center">方向</th>
   		<!-- <th field="MSISDN" width="80" align="center">MSISDN</th> -->
   		<!-- <th field="frameNumber" width="80" align="center">FrameNumber</th> -->
   		<th field="messageType" width="120" align="center">Um接口消息类型</th>
   		<th field="dataLayer" width="80" align="center">dataLayer</th>
   		<!--<th field="MS_Type" width="80" align="center">MS_Type</th> -->
   		<!-- <th field="l2" width="80" align="center">L2</th> -->
   		<th field="sourceIP" width="80" align="center">源IP地址</th>
   		<th field="destinationIP" width="80" align="center">目的IP地址</th>
   		<th field="dataLength" width="80" align="center">数据长度</th>
   		<th field="decoded" width="120" align="center">解码信息</th>
		<th field="LEVEL" width="120" align="center">LEVEL</th>
		<th field="SNR" width="150" align="center">SNR</th>
		<th field="QUALITY" width="120" align="center">QUALITY</th>
   		<th field="sourceCode" width="120" align="center">数据源码</th>
   		<th field="LAC" width="80" align="center">LAC</th>
   		<th field="CI" width="80" align="center">CI</th>
   		<th field="frontProcessorID" width="80" align="center">前置机号</th>
   		<th field="fileNo" width="80" align="center">记录号</th>
   		<!-- <th field="gkmMark" width="80" align="center">gkmMark</th> -->
   	</tr>
   </thead>
 </table>
 <div id="tb">
 	<div style="margin:3px">
 		<a href="javascript:exportGprs_defaultInCurrentPage()" class="easyui-linkbutton" iconCls="icon-save" plain="true">导出当前页MAC/RLC信令</a>
 		<a href="javascript:exportGprs_defaultInAllPages()" class="easyui-linkbutton" iconCls="icon-save" plain="true">导出所有页MAC/RLC信令</a>
 		<!-- <a href="javascript:exportByTemplateInCurrentPage()" class="easyui-linkbutton" iconCls="icon-save" plain="true">用模版导出当前MAC/RLC信令</a>
 		<a href="javascript:exportByTemplateInAllPages()" class="easyui-linkbutton" iconCls="icon-save" plain="true">用模版导出所有MAC/RLC信令</a> -->
 	 </div>
 	<div style="margin:3px">
 		&nbsp;&nbsp;小区：<select id="BSName" class="easyui-combotree" style="width:180px;" data-options="panelHeight:'auto', panelMaxHeight:'240px'" multiple></select>
 		&nbsp;&nbsp;时间：<input type="text" id="i1" style="width:calc(8%)" class="easyui-datetimebox"/>
 		&nbsp;至&nbsp;<input type="text" id="i2" style="width:calc(8%)" class="easyui-datetimebox"/>
 		<!--&nbsp;&nbsp;IMSI：<input type="text" style="width:calc(5%)" id="IMSI" name="IMSI" onkeydown="if(event.keyCode==13) searchGPRS_default()"/>-->
		&nbsp;&nbsp;Um接口消息类型：<select id="messageType1" class="easyui-combotree" style="width:320px;" multiple></select>&nbsp;&nbsp;
 		&nbsp;&nbsp;TLLI：<input type="text" style="width:calc(7%)" id="TLLI" name="TLLI" onkeydown="if(event.keyCode==13) searchGPRS_default()"/>
 		&nbsp;&nbsp;记录号：<input type="text" style="width:calc(7%)" id="recordId" name="recordId" onkeydown="if(event.keyCode==13) searchGPRS_default()"/>
 		
 		&nbsp;&nbsp;<input id="in1" class="easyui-searchbox" data-options="prompt:'Please Input Value',menu:'#mm'" style="width:210px; margin-top:-20px"></input>
		<div id="mm">
			<div data-options="name:'IMSI'">IMSI</div>
			<div data-options="name:'gTrainNo'">车次号</div>
			<div data-options="name:'CTCS_ID'">机车号</div>
		</div>
 		<!-- &nbsp;源端IP：&nbsp;<input type="text" size="25" id="SourceIP" name="SourceIP" onkeydown="if(event.keyCode==13) searchGPRS_default()"/>
 		&nbsp;目的IP：&nbsp;<input type="text" size="25" id="DestinationIP" name="DestinationIP" onkeydown="if(event.keyCode==13) searchGPRS_default()"/> -->
 		
 		<a href="javascript:searchGPRS_default()" class="easyui-linkbutton" iconCls="icon-search" plain="true"><b style="font-size:15px">查询</b></a>
 	</div>
 </div>
 
</body>
</html>